package com.yiwei.zxp.view;

import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.zxp.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-7-31.
 */

public class MyCommentTopLayout extends LinearLayout {
    @BindView(R.id.txt_one)
    TextView txtOne;
    @BindView(R.id.view_one)
    View viewOne;
    @BindView(R.id.txt_two)
    TextView txtTwo;
    @BindView(R.id.view_two)
    View viewTwo;
    @BindView(R.id.txt_three)
    TextView txtThree;
    @BindView(R.id.view_three)
    View viewThree;
    @BindView(R.id.txt_four)
    TextView txtFour;
    @BindView(R.id.view_four)
    View viewFour;
    @BindView(R.id.txt_five)
    TextView txtFive;
    @BindView(R.id.view_five)
    View viewFive;

    public MyCommentTopLayout(Context context) {
        super(context);
        init(context, null);
    }

    public MyCommentTopLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public MyCommentTopLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        inflate(context, R.layout.layout_comment_top, this);
    }

    private int mTextColor[] = new int[]{0xffFF0030, 0xff999999};

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.bind(this);
    }

    private void selectItem(int poi) {
        viewOne.setVisibility(View.GONE);
        viewTwo.setVisibility(View.GONE);
        viewThree.setVisibility(View.GONE);
        viewFour.setVisibility(View.GONE);
        viewFive.setVisibility(View.GONE);
        txtOne.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        txtTwo.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        txtThree.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        txtFour.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        txtFive.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        txtOne.setTextColor(0xff999999);
        txtTwo.setTextColor(0xff999999);
        txtThree.setTextColor(0xff999999);
        txtFour.setTextColor(0xff999999);
        txtFive.setTextColor(0xff999999);
        switch (poi) {
            case 0:
                viewOne.setVisibility(View.VISIBLE);
                txtOne.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                txtOne.setTextColor(0xffFF0030);
                break;
            case 1:
                viewTwo.setVisibility(View.VISIBLE);
                txtTwo.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                txtTwo.setTextColor(0xffFF0030);
                break;
            case 2:
                viewThree.setVisibility(View.VISIBLE);
                txtThree.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                txtThree.setTextColor(0xffFF0030);
                break;
            case 3:
                viewFour.setVisibility(View.VISIBLE);
                txtFour.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                txtFour.setTextColor(0xffFF0030);
                break;
            case 4:
                viewFive.setVisibility(View.VISIBLE);
                txtFive.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                txtFive.setTextColor(0xffFF0030);
                break;
        }
        if (onChooseListener != null) {
            onChooseListener.onClick(poi);
        }
    }

    @OnClick({R.id.txt_one, R.id.txt_two, R.id.txt_three, R.id.txt_four, R.id.txt_five})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.txt_one:
                selectItem(0);
                break;
            case R.id.txt_two:
                selectItem(1);
                break;
            case R.id.txt_three:
                selectItem(2);
                break;
            case R.id.txt_four:
                selectItem(3);
                break;
            case R.id.txt_five:
                selectItem(4);
                break;
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(int poi);

    }
}
